package com.api.shopapi.mapper;


import com.api.shopapi.entity.Complaint;
import com.api.shopapi.entity.dto.ComplaintDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
@Repository
@Mapper
public interface ComplaintMapper {


    @Insert("insert into complaint " +
            "(" +
            "ComplaintCode, " +
            "UserCode, " +
            "Type, " +
            "Remarks, " +
            "CreateTime, " +
            "GovernmentCode," +
            "Status," +
            "DisposeRemark" +
            ") " +
            "VALUES " +
            "(" +
            "#{complaint.ComplaintCode} ," +
            "#{complaint.UserCode} ," +
            "#{complaint.Type} ," +
            "#{complaint.Remarks} ," +
            "#{complaint.CreateTime} ," +
            "#{complaint.GovernmentCode}, " +
            "#{complaint.Status}, " +
            "#{complaint.DisposeRemark} " +
            ")")
    int insert(@Param("complaint") Complaint complaint);





    @Update("update complaint " +
            "set " +
            "ComplaintCode=#{ComplaintCode} ," +
            "UserCode=#{UserCode} ," +
            "Type=#{Type} ," +
            "Remarks=#{Remarks} ," +
            "CreateTime=#{CreateTime} ," +
            "GovernmentCode=#{GovernmentCode} ," +
            "Status=#{Status},  " +
            "DisposeRemark=#{DisposeRemark}  " +
            "where " +
            "ComplaintCode=#{ComplaintCode}   ")
    int update(Complaint complaint);


    @Select("<script>" +
            "select  c.* from  complaint as c   " +
            "left join user as u on c.UserCode=u.UserCode " +
            "where (c.CreateTime between #{startTime} and #{endTime}) and    u.GovernmentCode=#{governmentCode} " +
            "<if test =' status !=-1 '>" +
            " and  c.Status=#{status} " +
            "</if>" +
            "<if test =' type !=-1 '>" +
            " and  c.type=#{type} " +
            "</if>" +
            "</script>")
    List<ComplaintDTO> getPageList(@Param("governmentCode") String governmentCode,
                                   @Param("status") int status,
                                   @Param("type") int type,
                                   @Param("startTime") Date startTime,
                                   @Param("endTime") Date endTime);

    @Select("select * from complaint " +
            "where " +
            "ComplaintCode=#{complaintCode} ")
    ComplaintDTO getByComplaintCode(@Param("complaintCode") String complaintCode);


}
